package cn.math.appmath.action;

import org.apache.struts2.ServletActionContext;

import cn.math.appmath.bean.AchievementBean;
import cn.math.appmath.biz.AchievementBiz;
import cn.math.appmath.entity.Achievement;

import com.opensymphony.xwork2.ActionSupport;

public class AchievementAction extends ActionSupport {
	private static final long serialVersionUID = -4565898601842133546L;
	private Achievement achievement;
	private AchievementBiz achievementBiz;
	private AchievementBean achievementBean;
	private String message;
	private Integer[] nos;
	
	public String findAchievement(){
		String pageStr = ServletActionContext.getRequest().getParameter("page");
		int page = 0;
		if(pageStr != null && !"".equals(pageStr))
			page = Integer.parseInt(pageStr);
		String param = ServletActionContext.getRequest().getParameter("param");
		if(param == null || param.equals(""))
			param = "backward";
		achievementBean = achievementBiz.findAll(page, param);
		return SUCCESS;
	}
	
	public String achievementforward(){
		message = "";
		return SUCCESS;
	}
	/**
	 * 根据主键ID查找研究信息
	 * @return
	 */
	public String findById(){
		String idStr = ServletActionContext.getRequest().getParameter("id");
		int id  = 0;
		if(!"".equals(idStr) && idStr != null)
			id = Integer.parseInt(idStr);
		achievement = this.achievementBiz.findById(id);
		return SUCCESS;
	}
	
	/**
	 * 保存研究成果
	 * @return
	 */
	public String saveAchievement(){
		if(achievementBiz.save(achievement)){
			message = "保存研究成果信息成功";
			return SUCCESS;
		}
		message = "保存研究成果信息失败";
		return INPUT;
	}
	
	/**
	 * 删除研究信息
	 * @return
	 */
	public String deleteAchievement(){
		String noStr = ServletActionContext.getRequest().getParameter("no");
		if(noStr != null && !"".equals(noStr)){
			Integer no = new Integer(noStr);
			nos = new Integer[]{no};
		}
		if(this.achievementBiz.delete(nos)){
			return SUCCESS;
		}else{
			message = "删除研究成果信息失败";
			return INPUT;
		}
	}

	public Achievement getAchievement() {
		return achievement;
	}

	public void setAchievement(Achievement achievement) {
		this.achievement = achievement;
	}

	public AchievementBean getAchievementBean() {
		return achievementBean;
	}

	public void setAchievementBean(AchievementBean achievementBean) {
		this.achievementBean = achievementBean;
	}

	public void setAchievementBiz(AchievementBiz achievementBiz) {
		this.achievementBiz = achievementBiz;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Integer[] getNos() {
		return nos;
	}

	public void setNos(Integer[] nos) {
		this.nos = nos;
	}
}
